package com.ruoyi.apis.controller;

import com.ruoyi.apis.dto.ProjectMessageDTO;
import com.ruoyi.apis.service.MessageService;
import com.ruoyi.apis.vo.IndustryVO;
import com.ruoyi.common.core.domain.AjaxResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author Choi
 * @Date 2021/8/17
 */

@Api(value = "案例留言", tags = "案例留言相关接口")
@RestController
@RequestMapping("/api")
@Validated
public class PMessageController {

    @Autowired
    private MessageService messageService;

    /**
     * 行业列表
     */
    @ApiOperation(value = "行业列表")
    @GetMapping("/industies")
    public AjaxResult industry() {
        List<IndustryVO> industries = messageService.getIndustries();
        return AjaxResult.success(industries);
    }

    /**
     * 行业详情
     */
    @ApiOperation(value = "行业详情")
    @GetMapping("/industies/{industryId}")
    public AjaxResult industryDetail(@ApiParam(name = "industryId", value = "行业ID")
                                     @PathVariable long industryId) {
        IndustryVO industry = messageService.getIndustry(industryId);
        return AjaxResult.success(industry);
    }

    /**
     * 案例发布留言
     */
    @ApiOperation(value = "案例发布留言")
    @PostMapping("/projects/message")
    public AjaxResult createMessage(@RequestBody @Validated ProjectMessageDTO messageDTO) {
        messageService.createProjectMessage(messageDTO);
        return AjaxResult.success();
    }

}
